<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="robots" content="noodp" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
        <title>NTP协议简单分析 - Simple Life</title><meta name="Description" content="易娃的Blog"><meta property="og:title" content="NTP协议简单分析" />
<meta property="og:description" content="一.概述 NTP (Network Time Protocol, 网络时间协议) 是由 RFC 5905 定义的时间同步协议, 用来在分布式时间服务器和客户端之间进行时间同步, 是一个跨越广域网或局域网的复杂的同" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://alexwuyh.gitee.io/Blog/ntp%E5%8D%8F%E8%AE%AE%E7%AE%80%E5%8D%95%E5%88%86%E6%9E%90/" /><meta property="og:image" content="https://alexwuyh.gitee.io/logo.png"/><meta property="article:section" content="posts" />
<meta property="article:published_time" content="2022-01-29T00:00:00+00:00" />
<meta property="article:modified_time" content="2022-01-29T00:00:00+00:00" />

<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:image" content="https://alexwuyh.gitee.io/logo.png"/>

<meta name="twitter:title" content="NTP协议简单分析"/>
<meta name="twitter:description" content="一.概述 NTP (Network Time Protocol, 网络时间协议) 是由 RFC 5905 定义的时间同步协议, 用来在分布式时间服务器和客户端之间进行时间同步, 是一个跨越广域网或局域网的复杂的同"/>
<meta name="application-name" content="LoveIt">
<meta name="apple-mobile-web-app-title" content="LoveIt"><meta name="theme-color" content="#ffffff"><meta name="msapplication-TileColor" content="#da532c"><link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
        <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
        <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"><link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"><link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5"><link rel="manifest" href="/site.webmanifest"><link rel="canonical" href="https://alexwuyh.gitee.io/Blog/ntp%E5%8D%8F%E8%AE%AE%E7%AE%80%E5%8D%95%E5%88%86%E6%9E%90/" /><link rel="prev" href="https://alexwuyh.gitee.io/Blog/tcpdump%E5%91%BD%E4%BB%A4%E4%BD%BF%E7%94%A8%E7%AE%80%E4%BB%8B/" /><link rel="next" href="https://alexwuyh.gitee.io/Blog/linux%E7%B3%BB%E7%BB%9F%E5%90%AF%E5%8A%A8%E8%BF%87%E7%A8%8B/" /><link rel="stylesheet" href="/Blog/lib/normalize/normalize.min.css"><link rel="stylesheet" href="/Blog/css/style.min.css"><link rel="stylesheet" href="/Blog/lib/fontawesome-free/all.min.css"><link rel="stylesheet" href="/Blog/lib/animate/animate.min.css"><script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "BlogPosting",
        "headline": "NTP协议简单分析",
        "inLanguage": "zh-CN",
        "mainEntityOfPage": {
            "@type": "WebPage",
            "@id": "https:\/\/alexwuyh.gitee.io\/Blog\/ntp%E5%8D%8F%E8%AE%AE%E7%AE%80%E5%8D%95%E5%88%86%E6%9E%90\/"
        },"genre": "posts","keywords": "NTP, Network, Linux","wordcount":  3902 ,
        "url": "https:\/\/alexwuyh.gitee.io\/Blog\/ntp%E5%8D%8F%E8%AE%AE%E7%AE%80%E5%8D%95%E5%88%86%E6%9E%90\/","datePublished": "2022-01-29T00:00:00+00:00","dateModified": "2022-01-29T00:00:00+00:00","publisher": {
            "@type": "Organization",
            "name": ""},"author": {
                "@type": "Person",
                "name": "Alex Wu"
            },"description": ""
    }
    </script></head>
    <body header-desktop="fixed" header-mobile="auto"><script type="text/javascript">(window.localStorage && localStorage.getItem('theme') ? localStorage.getItem('theme') === 'dark' : ('auto' === 'auto' ? window.matchMedia('(prefers-color-scheme: dark)').matches : 'auto' === 'dark')) && document.body.setAttribute('theme', 'dark');</script>

        <div id="mask"></div><div class="wrapper"><header class="desktop" id="header-desktop">
    <div class="header-wrapper">
        <div class="header-title">
            <a href="/Blog/" title="Simple Life"><span id="id-1" class="typeit"></span></a>
        </div>
        <div class="menu">
            <div class="menu-inner"><a class="menu-item" href="/Blog/Blog/posts/"> 文章 </a><a class="menu-item" href="/Blog/Blog/tags/"> 标签 </a><a class="menu-item" href="/Blog/Blog/categories/"> 分类 </a><span class="menu-item delimiter"></span><span class="menu-item search" id="search-desktop">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-desktop">
                        <a href="javascript:void(0);" class="search-button search-toggle" id="search-toggle-desktop" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="javascript:void(0);" class="search-button search-clear" id="search-clear-desktop" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-desktop">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </span><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw"></i>
                </a>
            </div>
        </div>
    </div>
</header><header class="mobile" id="header-mobile">
    <div class="header-container">
        <div class="header-wrapper">
            <div class="header-title">
                <a href="/Blog/" title="Simple Life"><span id="id-2" class="typeit"></span></a>
            </div>
            <div class="menu-toggle" id="menu-toggle-mobile">
                <span></span><span></span><span></span>
            </div>
        </div>
        <div class="menu" id="menu-mobile"><div class="search-wrapper">
                    <div class="search mobile" id="search-mobile">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-mobile">
                        <a href="javascript:void(0);" class="search-button search-toggle" id="search-toggle-mobile" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="javascript:void(0);" class="search-button search-clear" id="search-clear-mobile" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-mobile">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </div>
                    <a href="javascript:void(0);" class="search-cancel" id="search-cancel-mobile">
                        取消
                    </a>
                </div><a class="menu-item" href="/Blog/Blog/posts/" title="">文章</a><a class="menu-item" href="/Blog/Blog/tags/" title="">标签</a><a class="menu-item" href="/Blog/Blog/categories/" title="">分类</a><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                <i class="fas fa-adjust fa-fw"></i>
            </a></div>
    </div>
</header>
<div class="search-dropdown desktop">
    <div id="search-dropdown-desktop"></div>
</div>
<div class="search-dropdown mobile">
    <div id="search-dropdown-mobile"></div>
</div>
<main class="main">
                <div class="container"><div class="toc" id="toc-auto">
            <h2 class="toc-title">目录</h2>
            <div class="toc-content" id="toc-content-auto"></div>
        </div><article class="page single"><h1 class="single-title animated flipInX">NTP协议简单分析</h1><div class="post-meta">
            <div class="post-meta-line"><span class="post-author"><a href="/Blog/" title="Author" rel=" author" class="author"><i class="fas fa-user-circle fa-fw"></i>Alex Wu</a></span>&nbsp;<span class="post-category">收录于 <a href="/Blog/categories/ntp/"><i class="far fa-folder fa-fw"></i>NTP</a>&nbsp;<a href="/Blog/categories/network/"><i class="far fa-folder fa-fw"></i>Network</a></span></div>
            <div class="post-meta-line"><i class="far fa-calendar-alt fa-fw"></i>&nbsp;<time datetime="2022-01-29">2022-01-29</time>&nbsp;<i class="fas fa-pencil-alt fa-fw"></i>&nbsp;约 3902 字&nbsp;
                <i class="far fa-clock fa-fw"></i>&nbsp;预计阅读 8 分钟&nbsp;<span id="/Blog/ntp%E5%8D%8F%E8%AE%AE%E7%AE%80%E5%8D%95%E5%88%86%E6%9E%90/" class="leancloud_visitors" data-flag-title="NTP协议简单分析">
                        <i class="far fa-eye fa-fw"></i>&nbsp;<span class=leancloud-visitors-count></span>&nbsp;次阅读
                    </span>&nbsp;</div>
        </div><div class="details toc" id="toc-static"  kept="true">
                <div class="details-summary toc-title">
                    <span>目录</span>
                    <span><i class="details-icon fas fa-angle-right"></i></span>
                </div>
                <div class="details-content toc-content" id="toc-content-static"><nav id="TableOfContents">
  <ul>
    <li><a href="#一概述">一.概述</a></li>
    <li><a href="#二工作原理">二.工作原理</a>
      <ul>
        <li><a href="#实现方式">实现方式</a></li>
        <li><a href="#工作流程">工作流程</a></li>
        <li><a href="#客户端服务器模式">客户端/服务器模式</a></li>
        <li><a href="#对称模式">对称模式</a></li>
        <li><a href="#广播模式">广播模式</a></li>
        <li><a href="#组播模式">组播模式</a></li>
      </ul>
    </li>
    <li><a href="#三ntp报文格式">三.NTP报文格式</a></li>
    <li><a href="#四实例分析">四.实例分析</a>
      <ul>
        <li><a href="#wireshark-抓包如下">wireshark 抓包如下:</a></li>
        <li><a href="#解析数据">解析数据</a></li>
      </ul>
    </li>
  </ul>
</nav></div>
            </div><div class="content" id="content"><h2 id="一概述">一.概述</h2>
<ul>
<li><strong>NTP</strong> (Network Time Protocol, 网络时间协议) 是由 <a href="https://tools.ietf.org/pdf/rfc5905.pdf" target="_blank" rel="noopener noreffer"><strong>RFC 5905</strong></a> 定义的时间同步协议, 用来在分布式时间服务器和客户端之间进行时间同步, 是一个跨越广域网或局域网的复杂的同步时间协议, 它通常可获得毫秒级的精度.</li>
<li><strong>NTP</strong> 基于 <strong>UDP</strong> 报文进行传输, 使用的UDP端口号为 <strong>123</strong>.</li>
<li>使用 NTP 的目的是对网络内所有具有时钟的设备进行时钟同步, 使网络内所有设备的时钟保持一致, 从而使设备能够提供基于统一时间的多种应用.</li>
<li>对于运行 NTP 的本地系统, 既可以接收来自其他时钟源的同步, 又可以作为时钟源同步其他的时钟, 并且可以和其他设备相互同步.</li>
</ul>
<h2 id="二工作原理">二.工作原理</h2>
<h3 id="实现方式">实现方式</h3>
<ul>
<li>无线时钟: 服务器系统可以通过串口连接一个无线时钟. 无线时钟接收 GPS 的卫星发射的信号来决定当前时间. 无线时钟是一个非常精确的时间源, 但是需要花一定的费用.</li>
<li>时间服务器: 还可以使用网络中 NTP 时间服务器, 通过这个服务器来同步网络中的系统的时钟.</li>
<li>局域网内的同步: 如果只是需要在本局域网内进行系统间的时钟同步, 那么就可以使用局域网中任何一个系统的时钟. 你需要选择局域网中的一个节点的时钟作”权威的”的时间源, 然后其它的节点就只需要与这个时间源进行时间同步即可. 使用这种方式, 所有的节点都会使用一个公共的系统时钟, 但是不需要和局域网外的系统进行时钟同步. 如果一个系统在一个局域网的内部, 同时又不能使用无线时钟, 这种方式是最好的选择.</li>
</ul>
<h3 id="工作流程">工作流程</h3>
<ul>
<li>Device A 和 Device B 通过网络相连, 有自己独立的系统时钟, 通过 NTP 实现各自系统时钟的自动同步.</li>
</ul>
<blockquote>
<p>Device A 和 Device B 的系统时钟同步之前, Device A 的时钟设定为 10:00:00 AM, Device B 的时钟设定为 11:00:00 AM.
Device B 作为 NTP 时间服务器, 即 Device A 使自己的时钟与 Device B 时钟同步.
NTP 报文在 Device A 和 Device B 之间单向传输所需要的时间为 1s.</p>
</blockquote>
<p><img
        class="lazyload"
        src="/Blog/svg/loading.min.svg"
        data-src="https://blog.srefan.com/assets/images/ntp/process.jpg"
        data-srcset="https://blog.srefan.com/assets/images/ntp/process.jpg, https://blog.srefan.com/assets/images/ntp/process.jpg 1.5x, https://blog.srefan.com/assets/images/ntp/process.jpg 2x"
        data-sizes="auto"
        alt="https://blog.srefan.com/assets/images/ntp/process.jpg"
        title="img_2" /></p>
<ol>
<li>Device A 发送一个NTP报文给 Device B, 该报文带有它离开 Device A 时的时间戳, 该时间戳为 10:00:00 AM (T1).</li>
<li>当此 NTP 报文到达 Device B 时, Device B 加上自己的时间戳, 该时间戳为 11:00:01 AM (T2).</li>
<li>当此 NTP 报文离开 Device B 时, Device B 加上自己的时间戳, 该时间戳为 11:00:02 AM (T3).</li>
<li>当 Device A 接收到该响应报文时, Device A 的本地时间为 10:00:03 AM (T4).</li>
</ol>
<ul>
<li>至此, Device A 已经拥有足够的信息来计算两个重要的参数:</li>
<li>NTP 报文的往返时延 Delay = (T4-T1) - (T3-T2) = 2s.</li>
<li>Device A 相对 Device B 的时间差 Offset = ((T2-T1) + (T3-T4))/2 = 1h.</li>
<li>这样, Device A 就能够根据这些信息来设定自己的时钟, 使之与 Device B 的时钟同步.</li>
<li>设备可以采用多种 NTP 工作模式进行时间同步:
<ol>
<li>客户端/服务器模式</li>
<li>对称模式</li>
<li>广播模式</li>
<li>组播模式</li>
</ol>
</li>
</ul>
<h3 id="客户端服务器模式">客户端/服务器模式</h3>
<ul>
<li>在客户端/服务器模式中, 客户端向服务器发送时钟同步报文, 报文中的 Mode 字段设置为3 (客户模式). 服务器端收到报文后会自动工作在服务器模式, 并发送应答报文, 报文中的 Mode 字段设置为4 (服务器模式). 客户端收到应答报文后, 进行时钟过滤和选择, 并同步到优选的服务器.</li>
<li>在该模式下, 客户端能同步到服务器, 而服务器无法同步到客户端.</li>
</ul>
<p><img
        class="lazyload"
        src="/Blog/svg/loading.min.svg"
        data-src="https://blog.srefan.com/assets/images/ntp/client_server.jpg"
        data-srcset="https://blog.srefan.com/assets/images/ntp/client_server.jpg, https://blog.srefan.com/assets/images/ntp/client_server.jpg 1.5x, https://blog.srefan.com/assets/images/ntp/client_server.jpg 2x"
        data-sizes="auto"
        alt="https://blog.srefan.com/assets/images/ntp/client_server.jpg"
        title="img_3" /></p>
<h3 id="对称模式">对称模式</h3>
<ul>
<li>在对称模式中, 主动对称体和被动对称体之间首先交互 Mode 字段为 3 (客户端模式) 和 4 (服务器模式) 的NTP报文. 之后, 主动对称体向被动对称体发送时钟同步报文, 报文中的 Mode 字段设置为 1 (主动对称体), 被动对等体收到报文后自动工作在被动对等体模式, 并发送应答报文, 报文中的Mode字段设置为 2 (被动对等体). 经过报文的交互, 对等体模式建立起来. 主动对等体和被动对等体可以互相同步. 如果双方的时钟都已经同步, 则以层数小的时钟为准.</li>
</ul>
<p><img
        class="lazyload"
        src="/Blog/svg/loading.min.svg"
        data-src="https://blog.srefan.com/assets/images/ntp/peer.jpg"
        data-srcset="https://blog.srefan.com/assets/images/ntp/peer.jpg, https://blog.srefan.com/assets/images/ntp/peer.jpg 1.5x, https://blog.srefan.com/assets/images/ntp/peer.jpg 2x"
        data-sizes="auto"
        alt="https://blog.srefan.com/assets/images/ntp/peer.jpg"
        title="img_4" /></p>
<h3 id="广播模式">广播模式</h3>
<ul>
<li>在广播模式中, 服务器端周期性地向广播地址 <code>255.255.255.255</code> 发送时钟同步报文, 报文中的 Mode 字段设置为5 (广播模式). 客户端侦听来自服务器的广播报文. 当客户端接收到第一个广播报文后, 客户端与服务器交互 Mode 字段为3 (客户模式) 和 4 (服务器模式) 的NTP报文, 以获得客户端与服务器间的网络延迟. 之后, 客户端就进入广播客户端模式, 继续侦听广播报文的到来, 根据到来的广播报文对系统时钟进行同步.</li>
</ul>
<p><img
        class="lazyload"
        src="/Blog/svg/loading.min.svg"
        data-src="https://blog.srefan.com/assets/images/ntp/broadcast.jpg"
        data-srcset="https://blog.srefan.com/assets/images/ntp/broadcast.jpg, https://blog.srefan.com/assets/images/ntp/broadcast.jpg 1.5x, https://blog.srefan.com/assets/images/ntp/broadcast.jpg 2x"
        data-sizes="auto"
        alt="https://blog.srefan.com/assets/images/ntp/broadcast.jpg"
        title="img_5" /></p>
<h3 id="组播模式">组播模式</h3>
<ul>
<li>在组播模式中, 服务器端周期性地向用户配置的组播地址 (若用户没有配置组播地址, 则使用默认的 NTP 组播地址224.0.1.1) 发送时钟同步报文, 报文中的 Mode 字段设置为 5 (组播模式). 客户端侦听来自服务器的组播报文. 当客户端接收到第一个组播报文后, 客户端与服务器交互 Mode 字段为 3 (客户模式) 和 4 (服务器模式) 的 NTP 报文, 以获得客户端与服务器间的网络延迟. 之后, 客户端就进入组播客户模式, 继续侦听组播报文的到来, 根据到来的组播报文对系统时钟进行同步.</li>
</ul>
<p><img
        class="lazyload"
        src="/Blog/svg/loading.min.svg"
        data-src="https://blog.srefan.com/assets/images/ntp/mutlicast.jpg"
        data-srcset="https://blog.srefan.com/assets/images/ntp/mutlicast.jpg, https://blog.srefan.com/assets/images/ntp/mutlicast.jpg 1.5x, https://blog.srefan.com/assets/images/ntp/mutlicast.jpg 2x"
        data-sizes="auto"
        alt="https://blog.srefan.com/assets/images/ntp/mutlicast.jpg"
        title="img_6" /></p>
<h2 id="三ntp报文格式">三.NTP报文格式</h2>
<ul>
<li><strong>NTP</strong> 有两种不同类型的报文, 一种是 <strong>时钟同步报文</strong>, 一种是 <strong>控制报文</strong>.</li>
<li><strong>控制报文</strong> 仅用于需要网络管理的场合, 对于时钟同步功能不是必需的, 暂不做分析.</li>
<li>时钟同步报文格式如下:</li>
</ul>
<p><img
        class="lazyload"
        src="/Blog/svg/loading.min.svg"
        data-src="https://blog.srefan.com/assets/images/ntp/ntp_format.jpg"
        data-srcset="https://blog.srefan.com/assets/images/ntp/ntp_format.jpg, https://blog.srefan.com/assets/images/ntp/ntp_format.jpg 1.5x, https://blog.srefan.com/assets/images/ntp/ntp_format.jpg 2x"
        data-sizes="auto"
        alt="https://blog.srefan.com/assets/images/ntp/ntp_format.jpg"
        title="img_1" /></p>
<ul>
<li>LI (Leap Indicator): 闰秒标识器, 长度为 2 Bits, 用来预警最近一分钟插入 1s 或者删除 1s.</li>
</ul>
<table>
<thead>
<tr>
<th style="text-align:center">LI</th>
<th style="text-align:center">Value</th>
<th style="text-align:center">含义</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">00</td>
<td style="text-align:center">0</td>
<td style="text-align:center">无预告</td>
</tr>
<tr>
<td style="text-align:center">01</td>
<td style="text-align:center">1</td>
<td style="text-align:center">醉经一分钟有 61s</td>
</tr>
<tr>
<td style="text-align:center">10</td>
<td style="text-align:center">2</td>
<td style="text-align:center">最近一分钟有 59s</td>
</tr>
<tr>
<td style="text-align:center">11</td>
<td style="text-align:center">3</td>
<td style="text-align:center">警告状态(时钟未同步)</td>
</tr>
</tbody>
</table>
<ul>
<li>
<p>VN (Version Number): 版本号, 长度为 3 Bits, 目前最新的版本是 4, 向下兼容指定于 <a href="https://tools.ietf.org/pdf/rfc1305.pdf" target="_blank" rel="noopener noreffer"><strong>RFC 1305</strong></a> 的版本 3.</p>
</li>
<li>
<p>Mode: 工作模式, 长度为 3 Bits.</p>
<blockquote>
<p>点对点模式下, 客户端请求时设置此字段为 3, 服务器应答时设置此字段为 4.
广播模式下, 服务器应答设置此字段为 5.</p>
</blockquote>
</li>
</ul>
<table>
<thead>
<tr>
<th style="text-align:center">Mode</th>
<th style="text-align:center">Value</th>
<th style="text-align:center">含义</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">000</td>
<td style="text-align:center">0</td>
<td style="text-align:center">保留</td>
</tr>
<tr>
<td style="text-align:center">001</td>
<td style="text-align:center">1</td>
<td style="text-align:center">主动对称模式</td>
</tr>
<tr>
<td style="text-align:center">010</td>
<td style="text-align:center">2</td>
<td style="text-align:center">被动对称模式</td>
</tr>
<tr>
<td style="text-align:center">011</td>
<td style="text-align:center">3</td>
<td style="text-align:center">客户端模式</td>
</tr>
<tr>
<td style="text-align:center">100</td>
<td style="text-align:center">4</td>
<td style="text-align:center">服务器模式</td>
</tr>
<tr>
<td style="text-align:center">101</td>
<td style="text-align:center">5</td>
<td style="text-align:center">广播或组播模式</td>
</tr>
<tr>
<td style="text-align:center">110</td>
<td style="text-align:center">6</td>
<td style="text-align:center">NTP控制报文</td>
</tr>
<tr>
<td style="text-align:center">111</td>
<td style="text-align:center">7</td>
<td style="text-align:center">预留给内部使用</td>
</tr>
</tbody>
</table>
<ul>
<li>Stratum: 系统时钟的层数, 长度为 8 Bits, 取值范围 1~16, 定义时钟的准确度. 层数为 1 的时钟准确度最高, 准确度从 1 到 16 依次递减, 阶层的上限为15, 层数为 16的时钟处于<strong>未同步</strong>状态, 不能作为参考时钟.</li>
<li>NTP 获得 UTC 的时间来源可以是原子钟, 天文台, 卫星, 也可以从Internet上获取.</li>
<li>stratum-0 是高精度计时设备, 例如原子钟 (如铯, 铷), GPS时钟或其他无线电时钟. 它们生成非常精确的脉冲秒信号, 触发所连接计算机上的中断和时间戳. 也称为参考 (基准) 时钟.</li>
<li>stratum-1 是与 stratum-0 设备相连, 在几微秒误差内同步系统时钟的计算机.</li>
<li>时间是按 NTP 服务器的等级传播. 按照距离外部 UTC 源的远近将所有服务器归入不同的 Stratum (层) 中. Stratum-1 在顶层, 有外部 UTC 接入, 而Stratum-2 则从 Stratum-1 获取时间, Stratum-3 从 Stratum-2 获取时间, 以此类推, 但 Stratum 层的总数限制在15以内. 所有这些服务器在逻辑上形成阶梯式的架构并相互连接, 而 Stratum-1 的时间服务器是整个系统的基础.</li>
</ul>
<table>
<thead>
<tr>
<th style="text-align:center">stratum</th>
<th style="text-align:center">含义</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">0</td>
<td style="text-align:center">未指定或者难以获得</td>
</tr>
<tr>
<td style="text-align:center">1</td>
<td style="text-align:center">主要参考(如: 无线电时钟,校正的原子时钟)</td>
</tr>
<tr>
<td style="text-align:center">2~15</td>
<td style="text-align:center">第二参考(Via NTP)</td>
</tr>
<tr>
<td style="text-align:center">16</td>
<td style="text-align:center">未同步状态, 不能作为参考时钟</td>
</tr>
</tbody>
</table>
<ul>
<li>Poll: 轮询间隔时间, 长度为 8 Bits, 两个连续NTP报文之间的时间间隔, 用 2 的幂来表示, 比如值为 6 表示最小间隔为 2^6 = 64s.</li>
<li>Precision: 系统时钟的精度, 长度为 8 Bits, 用 2 的幂来表示, 比如 50Hz(20ms)或者60Hz(16.67ms) 可以表示成值 -5 (2^-5 = 0.03125s = 31.25ms).</li>
<li>Root Delay: 本地到主参考时钟源的往返时间, 长度为 32 Bits, 有 15～16 位小数部分的无符号定点小数.</li>
<li>Root Dispersion: 系统时钟相对于主参考时钟的最大误差, 长度为 32 Bits, 有 15～16 位小数部分的无符号定点小数.</li>
</ul>
<blockquote>
<p>网络对称性:
通过两次测量来估计链路延迟一般估算方法是假设链路是对称的, 即时间服务器到客户端的延迟等于客户端到时间服务器的延迟.
这种假设是理想化的, 实际的无线链路往往受到各种因素影响,
例如 多径, 时变 而不完全对称.
网络的拓扑结构:
简单的点对点拓扑结构能达到较高的同步精度, 而一些复杂的网络容易受到网络延迟抖动的影响, 且精度与网络负载情况相关.</p>
</blockquote>
<ul>
<li>Reference Identifier: 参考时钟源的标识, 长度为 32 Bits.</li>
<li>Reference Timestamp: 系统时钟最后一次被设定或更新的时间, 长度为 64 Bits, 无符号定点数, 前 32 Bits 表示整数部分, 后 32 Bits 表示小数部分, 理论分辨率 2^−32s.</li>
</ul>
<blockquote>
<p>时间戳的记录以秒的形式从 1900-01-01 00:00:00 算起.
NTP的时间精度在 WAN 为 数十毫秒,
在 LAN 为 亚毫秒级甚至更高,
在 Internet 上绝大部分能提供 1-50ms 的精确度, 取决于同步源和网络路径等特性.
比如: 当前时间为 1902-01-01 01:01:01, 与 1900 的参考时间相差为:
(365<em>2</em>24<em>60</em>60+3600+60+1) = 63075661s = 0x03C2754D s.
转换成二进制: 0000 0011 1100 0010 0111 0101 0100 1101 XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX.
因为只有 32 Bits 表示秒数, 所以到了 2036 年数据就会溢出.
所以以 136 年为一个周期置 0 , 会用一些外部的方法来表示是相对于 1900 年还是 2036 年的时间.
NTP 的未来版本可能将时间表示扩展到 128 Bits: 其中 64 Bits 表示秒, 64 Bits 表示秒的小数. 当前的 NTPv4 格式支持 “时代数字” (Era Number)和 “时代偏移” (Era Offset), 正确使用它们应该有助于解决日期翻转问题. 据Mills称: “64 Bits 秒的小数足以分辨光子以光速通过电子所需的时间. 64 Bits 的秒足以提供明确的时间表示, 直到宇宙变暗.”</p>
</blockquote>
<ul>
<li>Originate Timestamp: NTP请求报文离开发送端时发送端的本地时间, 长度为 64 Bits.</li>
<li>Receive Timestamp: NTP请求报文到达接收端时接收端的本地时间, 长度为 64 Bits.</li>
<li>Transmit Timestamp: 应答报文离开应答者时应答者的本地时间, 长度为 64 Bits.</li>
<li>Authenticator(Optional): 验证信息, 长度为 96 Bits, (可选信息), 当实现了 NTP 认证模式时, 主要标识符和信息数字域就包括已定义的信息认证代码 (MAC) 信息.</li>
</ul>
<blockquote>
<p>识别机制抗干扰和恶意破坏:
为防止对时间服务器的恶意破坏, NTP使用了识别 (Authentication) 机制.
检查来对时的信息是否是真正来自所宣称的服务器并检查资料的返回路径, 以提供对抗干扰的保护机制.</p>
</blockquote>
<h2 id="四实例分析">四.实例分析</h2>
<ul>
<li>时间服务器接收同步消息,应答反馈的数据如下:</li>
<li><code>1c0104ec 00000000 00000048 47505373 dd26aa9f f7e47f4e dd26aaa7 4f5022d9 dd26aaa7 5f6f1524 dd26aaa7 5f716a6a</code></li>
<li>长度为 48 Bytes.</li>
</ul>
<h3 id="wireshark-抓包如下">wireshark 抓包如下:</h3>
<p><img
        class="lazyload"
        src="/Blog/svg/loading.min.svg"
        data-src="http://static.zybuluo.com/AlexWuYh/b2326878yjx970c88mxlak6p/ntp-test-20191031.pcap"
        data-srcset="http://static.zybuluo.com/AlexWuYh/b2326878yjx970c88mxlak6p/ntp-test-20191031.pcap, http://static.zybuluo.com/AlexWuYh/b2326878yjx970c88mxlak6p/ntp-test-20191031.pcap 1.5x, http://static.zybuluo.com/AlexWuYh/b2326878yjx970c88mxlak6p/ntp-test-20191031.pcap 2x"
        data-sizes="auto"
        alt="http://static.zybuluo.com/AlexWuYh/b2326878yjx970c88mxlak6p/ntp-test-20191031.pcap"
        title="ntp-test-20191031.pcap-20016.5kB" /></p>
<p><img
        class="lazyload"
        src="/Blog/svg/loading.min.svg"
        data-src="https://blog.srefan.com/assets/images/ntp/example.jpg"
        data-srcset="https://blog.srefan.com/assets/images/ntp/example.jpg, https://blog.srefan.com/assets/images/ntp/example.jpg 1.5x, https://blog.srefan.com/assets/images/ntp/example.jpg 2x"
        data-sizes="auto"
        alt="https://blog.srefan.com/assets/images/ntp/example.jpg"
        title="mg_7" /></p>
<h3 id="解析数据">解析数据</h3>
<ul>
<li><code>1c0104ec</code>转换成二进制:<code>0001 1100 0000 0001 0000 0100 1110 1100</code></li>
</ul>
<ol>
<li>00.. …. = Leap Indicator: no warning (0)</li>
<li>..01 1… = Version Number: NTP Version 3 (3)</li>
<li>…. .100 = Mode: Server (4)</li>
<li>0000 0001 = Peer Clock Stratum: primary reference (1)</li>
<li>0000 0100 = Peer Polling Interval: 4 (2^4 = 16s)</li>
<li>1110 1100 = Peer Clock Precision: -20 (2^-20 = 0.000001s). ps: (补码: <code>1110 1100</code>, 转换为反码: <code>1110 1011</code>, 转换为原码: <code>0001 0100</code> = <code>20</code>. 添加符号为 <code>-20</code>, 精度为 <code>2^-20 = 0.000001s</code>.)</li>
</ol>
<ul>
<li>
<p><code>00000000</code> 秒数为 <code>0000</code>, 秒的小数为 <code>0000</code>. 所以: Root Delay: 0.0000s</p>
</li>
<li>
<p><code>00000048</code> 秒数为 <code>0000</code>, 秒的小数为 <code>0048</code>, 转换二进制: <code>0000 0000 0100 1000</code>. Root Dispersion: (0 + 2^-10 + 2^-13 = 0.0011s).</p>
</li>
<li>
<p><code>47505373</code> 采用ASCII码, Reference ID: Unidentified reference source ‘GPSs’</p>
</li>
<li>
<p><code>dd26aa9f f7e47f4e</code> 秒数为 <code>dd26aa9f</code>, 转换成 Unix 时间戳 (1900年 转换为 1970年开始): <code>0xdd26aa9f</code> - <code>0x83aa7e80</code> = <code>0x597c2c1f</code> = <code>1501309983</code> 即 <code>2017-07-29 14:33:03</code>. 秒的小数为 <code>f7e47f4e</code>, 转换成二进制: <code>1111 0111 1110 0100 0111 1111 0100 1110</code> = <code>2^-1 + 2^-2 + 2^-3 + 2^-4 + 2^-6 + 2^-7 + 2^-8 + 2^-9 + 2^-10 + 2^-11 + 2^-14 + 2^-18 + 2^-19 + 2^-20 + 2^-21 + 2^-22 + 2^-23 + 2^-24 + 2^-26 + 2^-29 + 2^-30 + 2^-31 = 0.968330000</code>. Reference Timestamp: 2017-07-29 14:33:03.068330000s UTC +08:00.</p>
</li>
<li>
<p><code>dd26aaa7 4f5022d9</code> 秒数为 <code>dd26aaa7</code> = <code>2017-07-29 14:33:11</code>. 秒的小数为 <code>4f5022d9</code> = <code>0.309816000</code>. Reference Timestamp: 2017-07-29 14:33:11.309816000s UTC +08:00.</p>
</li>
<li>
<p><code>dd26aaa7 5f6f1524</code> 秒数为 <code>dd26aaa7</code> = <code>2017-07-29 14:33:11</code>. 秒的小数为 <code>5f6f1524</code> = <code>0.372788000</code>. Reference Timestamp: 2017-07-29 14:33:11.372788000s UTC +08:00.</p>
</li>
<li>
<p><code>dd26aaa7 5f716a6a</code> 秒数为 <code>dd26aaa7</code> = <code>2017-07-29 14:33:11</code>. 秒的小数为 <code>5f716a6a</code> = <code>0.372824000</code>. Reference Timestamp: 2017-07-29 14:33:11.372824000s UTC +08:00.</p>
</li>
</ul>
</div><div class="post-footer" id="post-footer">
    <div class="post-info">
        <div class="post-info-line">
            <div class="post-info-mod">
                <span>更新于 2022-01-29</span>
            </div>
            <div class="post-info-license"></div>
        </div>
        <div class="post-info-line">
            <div class="post-info-md"><span>
                            <a class="link-to-markdown" href="/Blog/ntp%E5%8D%8F%E8%AE%AE%E7%AE%80%E5%8D%95%E5%88%86%E6%9E%90/index.md" target="_blank">阅读原始文档</a>
                        </span></div>
            <div class="post-info-share">
                <span><a href="javascript:void(0);" title="分享到 Twitter" data-sharer="twitter" data-url="https://alexwuyh.gitee.io/Blog/ntp%E5%8D%8F%E8%AE%AE%E7%AE%80%E5%8D%95%E5%88%86%E6%9E%90/" data-title="NTP协议简单分析" data-via="Alex_WuYh" data-hashtags="NTP,Network,Linux"><i class="fab fa-twitter fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Facebook" data-sharer="facebook" data-url="https://alexwuyh.gitee.io/Blog/ntp%E5%8D%8F%E8%AE%AE%E7%AE%80%E5%8D%95%E5%88%86%E6%9E%90/" data-hashtag="NTP"><i class="fab fa-facebook-square fa-fw"></i></a><a href="javascript:void(0);" title="分享到 WhatsApp" data-sharer="whatsapp" data-url="https://alexwuyh.gitee.io/Blog/ntp%E5%8D%8F%E8%AE%AE%E7%AE%80%E5%8D%95%E5%88%86%E6%9E%90/" data-title="NTP协议简单分析" data-web><i class="fab fa-whatsapp fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Line" data-sharer="line" data-url="https://alexwuyh.gitee.io/Blog/ntp%E5%8D%8F%E8%AE%AE%E7%AE%80%E5%8D%95%E5%88%86%E6%9E%90/" data-title="NTP协议简单分析"><i data-svg-src="/Blog/lib/simple-icons/icons/line.min.svg"></i></a><a href="javascript:void(0);" title="分享到 微博" data-sharer="weibo" data-url="https://alexwuyh.gitee.io/Blog/ntp%E5%8D%8F%E8%AE%AE%E7%AE%80%E5%8D%95%E5%88%86%E6%9E%90/" data-title="NTP协议简单分析" data-ralateuid="AlexWuYh"><i class="fab fa-weibo fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Myspace" data-sharer="myspace" data-url="https://alexwuyh.gitee.io/Blog/ntp%E5%8D%8F%E8%AE%AE%E7%AE%80%E5%8D%95%E5%88%86%E6%9E%90/" data-title="NTP协议简单分析" data-description=""><i data-svg-src="/Blog/lib/simple-icons/icons/myspace.min.svg"></i></a><a href="javascript:void(0);" title="分享到 Blogger" data-sharer="blogger" data-url="https://alexwuyh.gitee.io/Blog/ntp%E5%8D%8F%E8%AE%AE%E7%AE%80%E5%8D%95%E5%88%86%E6%9E%90/" data-title="NTP协议简单分析" data-description=""><i class="fab fa-blogger fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Evernote" data-sharer="evernote" data-url="https://alexwuyh.gitee.io/Blog/ntp%E5%8D%8F%E8%AE%AE%E7%AE%80%E5%8D%95%E5%88%86%E6%9E%90/" data-title="NTP协议简单分析"><i class="fab fa-evernote fa-fw"></i></a></span>
            </div>
        </div>
    </div>

    <div class="post-info-more">
        <section class="post-tags"><i class="fas fa-tags fa-fw"></i>&nbsp;<a href="/Blog/tags/ntp/">NTP</a>,&nbsp;<a href="/Blog/tags/network/">Network</a>,&nbsp;<a href="/Blog/tags/linux/">Linux</a></section>
        <section>
            <span><a href="javascript:void(0);" onclick="window.history.back();">返回</a></span>&nbsp;|&nbsp;<span><a href="/Blog/">主页</a></span>
        </section>
    </div>

    <div class="post-nav"><a href="/Blog/tcpdump%E5%91%BD%E4%BB%A4%E4%BD%BF%E7%94%A8%E7%AE%80%E4%BB%8B/" class="prev" rel="prev" title="tcpdump命令使用简介"><i class="fas fa-angle-left fa-fw"></i>tcpdump命令使用简介</a>
            <a href="/Blog/linux%E7%B3%BB%E7%BB%9F%E5%90%AF%E5%8A%A8%E8%BF%87%E7%A8%8B/" class="next" rel="next" title="Linux系统启动过程">Linux系统启动过程<i class="fas fa-angle-right fa-fw"></i></a></div>
</div>
<div id="comments"><div id="valine" class="comment"></div><noscript>
                Please enable JavaScript to view the comments powered by <a href="https://valine.js.org/">Valine</a>.
            </noscript></div></article></div>
            </main><footer class="footer">
        <div class="footer-container"><div class="footer-line">由 <a href="https://gohugo.io/" target="_blank" rel="noopener noreffer" title="Hugo 0.92.0">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/dillonzq/LoveIt" target="_blank" rel="noopener noreffer" title="LoveIt 0.2.10"><i class="far fa-kiss-wink-heart fa-fw"></i> LoveIt</a>
                </div><div class="footer-line"><i class="far fa-copyright fa-fw"></i><span itemprop="copyrightYear">2020 - 2022</span><span class="author" itemprop="copyrightHolder">&nbsp;<a href="/Blog/" target="_blank">Alex Wu</a></span>&nbsp;|&nbsp;<span class="license"><a rel="license external nofollow noopener noreffer" href="https://creativecommons.org/licenses/by-nc/4.0/" target="_blank">CC BY-NC 4.0</a></span><span class="icp-splitter">&nbsp;|&nbsp;</span><br class="icp-br"/>
                    <span class="icp">蜀ICP备20004229号-1</span></div>
        </div>
    </footer></div>

        <div id="fixed-buttons"><a href="#" id="back-to-top" class="fixed-button" title="回到顶部">
                <i class="fas fa-arrow-up fa-fw"></i>
            </a><a href="#" id="view-comments" class="fixed-button" title="查看评论">
                <i class="fas fa-comment fa-fw"></i>
            </a>
        </div><link rel="stylesheet" href="/Blog/lib/valine/valine.min.css"><link rel="stylesheet" href="/Blog/lib/katex/katex.min.css"><link rel="stylesheet" href="/Blog/lib/katex/copy-tex.min.css"><link rel="stylesheet" href="/Blog/lib/cookieconsent/cookieconsent.min.css"><script type="text/javascript" src="/Blog/lib/valine/Valine.min.js"></script><script type="text/javascript" src="/Blog/lib/smooth-scroll/smooth-scroll.min.js"></script><script type="text/javascript" src="/Blog/lib/autocomplete/autocomplete.min.js"></script><script type="text/javascript" src="/Blog/lib/lunr/lunr.min.js"></script><script type="text/javascript" src="/Blog/lib/lunr/lunr.stemmer.support.min.js"></script><script type="text/javascript" src="/Blog/lib/lunr/lunr.zh.min.js"></script><script type="text/javascript" src="/Blog/lib/lazysizes/lazysizes.min.js"></script><script type="text/javascript" src="/Blog/lib/clipboard/clipboard.min.js"></script><script type="text/javascript" src="/Blog/lib/sharer/sharer.min.js"></script><script type="text/javascript" src="/Blog/lib/typeit/typeit.min.js"></script><script type="text/javascript" src="/Blog/lib/katex/katex.min.js"></script><script type="text/javascript" src="/Blog/lib/katex/auto-render.min.js"></script><script type="text/javascript" src="/Blog/lib/katex/copy-tex.min.js"></script><script type="text/javascript" src="/Blog/lib/katex/mhchem.min.js"></script><script type="text/javascript" src="/Blog/lib/cookieconsent/cookieconsent.min.js"></script><script type="text/javascript">window.config={"code":{"copyTitle":"复制到剪贴板","maxShownLines":10},"comment":{"valine":{"appId":"o5gq6eLbupSlKq678zx1aKcd-gzGzoHsz","appKey":"S2CU3haJIhCbfVoIxhtrIzNp","avatar":"mp","el":"#valine","emojiCDN":"https://cdn.jsdelivr.net/npm/emoji-datasource-google@5.0.1/img/google/64/","emojiMaps":{"100":"1f4af.png","alien":"1f47d.png","anger":"1f4a2.png","angry":"1f620.png","anguished":"1f627.png","astonished":"1f632.png","black_heart":"1f5a4.png","blue_heart":"1f499.png","blush":"1f60a.png","bomb":"1f4a3.png","boom":"1f4a5.png","broken_heart":"1f494.png","brown_heart":"1f90e.png","clown_face":"1f921.png","cold_face":"1f976.png","cold_sweat":"1f630.png","confounded":"1f616.png","confused":"1f615.png","cry":"1f622.png","crying_cat_face":"1f63f.png","cupid":"1f498.png","dash":"1f4a8.png","disappointed":"1f61e.png","disappointed_relieved":"1f625.png","dizzy":"1f4ab.png","dizzy_face":"1f635.png","drooling_face":"1f924.png","exploding_head":"1f92f.png","expressionless":"1f611.png","face_vomiting":"1f92e.png","face_with_cowboy_hat":"1f920.png","face_with_hand_over_mouth":"1f92d.png","face_with_head_bandage":"1f915.png","face_with_monocle":"1f9d0.png","face_with_raised_eyebrow":"1f928.png","face_with_rolling_eyes":"1f644.png","face_with_symbols_on_mouth":"1f92c.png","face_with_thermometer":"1f912.png","fearful":"1f628.png","flushed":"1f633.png","frowning":"1f626.png","ghost":"1f47b.png","gift_heart":"1f49d.png","green_heart":"1f49a.png","grimacing":"1f62c.png","grin":"1f601.png","grinning":"1f600.png","hankey":"1f4a9.png","hear_no_evil":"1f649.png","heart":"2764-fe0f.png","heart_decoration":"1f49f.png","heart_eyes":"1f60d.png","heart_eyes_cat":"1f63b.png","heartbeat":"1f493.png","heartpulse":"1f497.png","heavy_heart_exclamation_mark_ornament":"2763-fe0f.png","hole":"1f573-fe0f.png","hot_face":"1f975.png","hugging_face":"1f917.png","hushed":"1f62f.png","imp":"1f47f.png","innocent":"1f607.png","japanese_goblin":"1f47a.png","japanese_ogre":"1f479.png","joy":"1f602.png","joy_cat":"1f639.png","kiss":"1f48b.png","kissing":"1f617.png","kissing_cat":"1f63d.png","kissing_closed_eyes":"1f61a.png","kissing_heart":"1f618.png","kissing_smiling_eyes":"1f619.png","laughing":"1f606.png","left_speech_bubble":"1f5e8-fe0f.png","love_letter":"1f48c.png","lying_face":"1f925.png","mask":"1f637.png","money_mouth_face":"1f911.png","nauseated_face":"1f922.png","nerd_face":"1f913.png","neutral_face":"1f610.png","no_mouth":"1f636.png","open_mouth":"1f62e.png","orange_heart":"1f9e1.png","partying_face":"1f973.png","pensive":"1f614.png","persevere":"1f623.png","pleading_face":"1f97a.png","pouting_cat":"1f63e.png","purple_heart":"1f49c.png","rage":"1f621.png","relaxed":"263a-fe0f.png","relieved":"1f60c.png","revolving_hearts":"1f49e.png","right_anger_bubble":"1f5ef-fe0f.png","robot_face":"1f916.png","rolling_on_the_floor_laughing":"1f923.png","scream":"1f631.png","scream_cat":"1f640.png","see_no_evil":"1f648.png","shushing_face":"1f92b.png","skull":"1f480.png","skull_and_crossbones":"2620-fe0f.png","sleeping":"1f634.png","sleepy":"1f62a.png","slightly_frowning_face":"1f641.png","slightly_smiling_face":"1f642.png","smile":"1f604.png","smile_cat":"1f638.png","smiley":"1f603.png","smiley_cat":"1f63a.png","smiling_face_with_3_hearts":"1f970.png","smiling_imp":"1f608.png","smirk":"1f60f.png","smirk_cat":"1f63c.png","sneezing_face":"1f927.png","sob":"1f62d.png","space_invader":"1f47e.png","sparkling_heart":"1f496.png","speak_no_evil":"1f64a.png","speech_balloon":"1f4ac.png","star-struck":"1f929.png","stuck_out_tongue":"1f61b.png","stuck_out_tongue_closed_eyes":"1f61d.png","stuck_out_tongue_winking_eye":"1f61c.png","sunglasses":"1f60e.png","sweat":"1f613.png","sweat_drops":"1f4a6.png","sweat_smile":"1f605.png","thinking_face":"1f914.png","thought_balloon":"1f4ad.png","tired_face":"1f62b.png","triumph":"1f624.png","two_hearts":"1f495.png","unamused":"1f612.png","upside_down_face":"1f643.png","weary":"1f629.png","white_frowning_face":"2639-fe0f.png","white_heart":"1f90d.png","wink":"1f609.png","woozy_face":"1f974.png","worried":"1f61f.png","yawning_face":"1f971.png","yellow_heart":"1f49b.png","yum":"1f60b.png","zany_face":"1f92a.png","zipper_mouth_face":"1f910.png","zzz":"1f4a4.png"},"enableQQ":false,"highlight":true,"lang":"zh-cn","pageSize":10,"placeholder":"你的评论 ...","recordIP":true,"visitor":true}},"cookieconsent":{"content":{"dismiss":"同意","link":"了解更多","message":"本网站使用 Cookies 来改善您的浏览体验."},"enable":true,"palette":{"button":{"background":"#f0f0f0"},"popup":{"background":"#1aa3ff"}},"theme":"edgeless"},"data":{"id-1":"Simple Life","id-2":"Simple Life"},"math":{"delimiters":[{"display":true,"left":"$$","right":"$$"},{"display":true,"left":"\\[","right":"\\]"},{"display":false,"left":"$","right":"$"},{"display":false,"left":"\\(","right":"\\)"}],"strict":false},"search":{"highlightTag":"em","lunrIndexURL":"/Blog/index.json","lunrLanguageCode":"zh","lunrSegmentitURL":"/Blog/lib/lunr/lunr.segmentit.js","maxResultLength":10,"noResultsFound":"没有找到结果","snippetLength":50,"type":"lunr"},"typeit":{"cursorChar":"|","cursorSpeed":1000,"data":{"id-1":["id-1"],"id-2":["id-2"]},"duration":-1,"speed":100}};</script><script type="text/javascript" src="/Blog/js/theme.min.js"></script><script type="text/javascript">
            window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}gtag('js', new Date());
            gtag('config', 'G-KJGDZS4RKJ', { 'anonymize_ip': true });
        </script><script type="text/javascript" src="https://www.googletagmanager.com/gtag/js?id=G-KJGDZS4RKJ" async></script></body>
</html>
